package cn.ld.module.system.dal.mapper.user;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.controller.admin.user.vo.user.UserPageInVO;
import cn.ld.module.system.dal.entity.user.AdminUserEntity;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

@Mapper
public interface AdminUserMapper extends BaseMapperX<AdminUserEntity> {

    default AdminUserEntity selectByUsername(String username) {
        return selectOne(AdminUserEntity::getUsername, username);
    }

    default AdminUserEntity selectByEmail(String email) {
        return selectOne(AdminUserEntity::getEmail, email);
    }

    default AdminUserEntity selectByMobile(String mobile) {
        return selectOne(AdminUserEntity::getMobile, mobile);
    }

    default PageResult<AdminUserEntity> selectPage(UserPageInVO inVO, Collection<Long> deptIds, Collection<Long> userIds) {
        return selectPage(inVO, new LambdaQueryWrapperX<AdminUserEntity>()
                .likeIfPresent(AdminUserEntity::getUsername, inVO.getUsername())
                .likeIfPresent(AdminUserEntity::getMobile, inVO.getMobile())
                .eqIfPresent(AdminUserEntity::getStatus, inVO.getStatus())
                .betweenIfPresent(AdminUserEntity::getCreateTime, inVO.getCreateTime())
                .inIfPresent(AdminUserEntity::getDeptId, deptIds)
                .inIfPresent(AdminUserEntity::getId, userIds)
                .orderByDesc(AdminUserEntity::getId));
    }

    default List<AdminUserEntity> selectListByNickname(String nickname) {
        return selectList(new LambdaQueryWrapperX<AdminUserEntity>().like(AdminUserEntity::getNickname, nickname));
    }

    default List<AdminUserEntity> selectListByStatus(Integer status) {
        return selectList(AdminUserEntity::getStatus, status);
    }

    default List<AdminUserEntity> selectListByDeptIds(Collection<Long> deptIds) {
        return selectList(AdminUserEntity::getDeptId, deptIds);
    }

}
